home *** CD-ROM | disk | FTP | other *** search
- .Na "dbconvert"
- .Aa
- .Fu
- Convert data from one datatype to another.
- .Ih "datatype conversion"
- .Sy
- .Sf "DBINT dbconvert(dbproc, srctype, src, srclen, desttype, dest, destlen)"
- .Sp "DBPROCESS" "*dbproc"
- .Sp "int" "srctype"
- .Sp "BYTE" "*src"
- .Sp "DBINT" "srclen"
- .Sp "int" "desttype"
- .Sp "BYTE" "*dest"
- .Sp "DBINT" "destlen"
- .Co
- .Bl
- This routine allows the program to convert data from one
- representation to another.
- To determine whether a particular conversion is permitted,
- the program can call \f2dbwillconvert()\f1 before attempting a conversion.
- .Bl
- \f2dbconvert()\f1 can convert data stored in
- any of the \*S datatypes (although, of course,
- not all conversions are legal):
- .sp
- .nf
- .in +5n
- .ta +25n
- .ne 12.5v
- \f3\*S type Program variable type\f1
- .sp 0.5v
- SYBCHAR DBCHAR
- .mc |
- SYBTEXT DBCHAR
- .mc
- SYBBINARY DBBINARY
- .mc |
- SYBIMAGE DBBINARY
- .mc
- SYBINT1 DBTINYINT
- SYBINT2 DBSMALLINT
- SYBINT4 DBINT
- SYBFLT8 DBFLT8
- SYBBIT DBBIT
- SYBMONEY DBMONEY
- SYBDATETIME DBDATETIME
- .fi
- .in -5n
- .sp 0.5v
- .Bl
- The table below lists the datatype conversions that
- \f2dbconvert()\f1 supports.
- The source datatypes are listed down the leftmost column and
- the destination datatypes are listed along the top row of the table.
- (For brevity, the prefix ``SYB'' has been eliminated from
- each datatype.)
- T (TRUE) indicates that the conversion is
- supported; F (FALSE) indicates that the conversion is not supported.
- .Ih "datatype conversion, supported"
- .sp
- .nf
- .in +3n
- .ps -4
- .vs -4
- .ta +17n +10n +10n +10n +10n +10n +10n +10n +10n +7n +13n
- .ne 17.5v
- \f3FROM: TO:\f1
- .sp 0.5v
- .mc |
- \f3 BIN- DATE-
- CHAR TEXT ARY IMAGE INT1 INT2 INT4 FLT8 BIT MONEY TIME\f1
- .ta +19n +10n +10n +10n +10n +10n +10n +10n +9n +10n +11n
- .sp 0.5v
- \f3CHAR\f1 T T T T T T T T T T T
- .sp 0.25v
- \f3TEXT\f1 T T T T T T T T T T T
- .sp 0.25v
- \f3BINARY\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3IMAGE\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3INT1\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3INT2\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3INT4\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3FLT8\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3BIT\f1 T T T T T T T T T F F
- .sp 0.25v
- \f3MONEY\f1 T T T T T T T T T T F
- .sp 0.25v
- \f3DATETIME\f1 T T T T F F F F F F T
- .fi
- .ps +4
- .vs +4
- .sp 0.5v
- .mc
- .in -3n
- .Bl
- A conversion to or from the datatypes SYBBINARY and SYBIMAGE
- is a straight bit-copy, except when the conversion involves
- SYBCHAR or SYBTEXT.
- When converting SYBCHAR or SYBTEXT data to SYBBINARY or SYBIMAGE, \f2dbconvert()\f1
- interprets the SYBCHAR or SYBTEXT string as hexadecimal, whether or
- not the string contains a leading ``0x''.
- When converting SYBBINARY or SYBIMAGE data to SYBCHAR or SYBTEXT, \f2dbconvert()\f1
- creates a hexadecimal string without a leading ``0x''.
- .Bl
- Converting a SYBMONEY, SYBCHAR, or SYBTEXT value to SYBFLT8 may result in some loss of precision.
- Converting a SYBFLT8 value to SYBCHAR or SYBTEXT may also result in some loss of precision.
- .Bl
- Converting a SYBFLT8 value to SYBMONEY can result in overflow, because the maximum value for
- SYBMONEY is $922,337,203,685,477.58.
- .Bl
- If overflow occurs when converting integer or float data to SYBCHAR or SYBTEXT,
- the first character of the resulting value will contain an asterisk (``*'') to indicate the error.
- .Bl
- A conversion to SYBBIT has the following effect:
- If the value being converted is not 0, the SYBBIT value will be set to 1; if the value \f2is\f1 0,
- the SYBBIT value will be set to 0.
- .Bl
- In certain cases, it can be useful to convert a datatype to itself.
- For instance, a conversion of SYBCHAR to SYBCHAR with a \f2destlen\f1 of -1 serves as
- a useful way to append a null terminator to a string, as the example below illustrates.
- .Bl
- Here's a short example that illustrates how to convert \*S data obtained with \f2dbdata()\f1:
- .ta +4n +4n +4n +4n +4n +4n
- .SD
- .so dbconvert.ex
- .ED
- In the \f2dbconvert()\f1 calls it was not necessary to cast the returns from \f2dbdata()\f1, because
- \f2dbdata()\f1 returns a BYTE pointer\(emprecisely the datatype
- \f2dbconvert()\f1 expects in the third parameter.
- .Bl
- If you're binding data to variables with \f2dbbind()\f1 rather than accessing the data directly
- with \f2dbdata()\f1,
- \f2dbbind()\f1 can perform the conversions itself, making \f2dbconvert()\f1 unnecessary.
- .Bl
- Example 5 in the \f2\*L Reference Supplement\f1 illustrates several more types of conversions using \f2dbconvert()\f1.
- .Bl
- For more information on \*S datatypes, see the \f2Commands Reference\f1 and the \f2types\f1 manual
- page in this document.
- .Bz
- .Pa
- .Pi dbproc
- A pointer to the DBPROCESS structure that provides the connection
- for a particular front-end/\*S process. It contains all the
- information that \*L uses to manage communications and data between the
- front end and \*S.
- In \f2dbconvert()\f1, the DBPROCESS is used only to supply any custom null
- values that the program may have specified via \f2dbsetnull()\f1.
- If \f2dbproc\f1 is NULL, \f2dbconvert()\f1 uses the default values
- for null value data conversions.
- .Pi srctype
- The datatype of the data which is to be converted.
- This parameter can be any of the \*S datatypes,
- as listed in the first table above.
- .Pi src
- A pointer to the data which is to be converted.
- If this pointer is NULL, \f2dbconvert()\f1 will place an appropriate
- null value in the destination variable.
- You can use \f2dbdata()\f1 to get the \*S data.
- .Pi srclen
- The length, in bytes, of the data to be converted.
- If the \f2srclen\f1 is 0, the source data is assumed to be null
- and \f2dbconvert()\f1 will place an appropriate null value
- in the destination variable.
- Otherwise,
- this length is ignored for all datatypes except character, text, binary, and image.
- For SYBCHAR data, a length of -1 indicates that the string is null-terminated.
- You can use \f2dbdatlen()\f1 to get the length of \*S data.
- .Pi desttype
- The datatype that the source data is to be converted into.
- This parameter can be any of the \*S datatypes,
- as listed in the first table above.
- .Pi dest
- A pointer to the destination variable that will receive the converted data.
- If this pointer is NULL, \f2dbconvert()\f1 will call the user-supplied error
- handler (if any) and return FAIL.
- .Pi destlen
- The length, in bytes, of the destination variable.
- \f2destlen\f1 is ignored for fixed-length datatypes.
- For a SYBCHAR destination, the value of \f2destlen\f1 must be the total length
- of the destination buffer space.
- A length of -1 for a SYBCHAR or SYBBINARY destination
- means that there is sufficient space available.
- In addition, for a SYBCHAR destination a length of -1 will cause the character string
- to be given a terminating null.
- .in -.375i
- .Re
- .br
- The length of the converted data, in bytes, if the datatype conversion succeeds.
- If the conversion fails, \f2dbconvert()\f1 returns -1.
- If \f2dbconvert()\f1 fails, it will first call a user-supplied error handler (if any)
- and set the global \*L error value.
- .sp
- This routine may fail for several reasons: the requested conversion was not available;
- the conversion resulted in truncation, overflow, or loss of precision in the destination
- variable; or a syntax error occurred in converting a character string to some numeric type.
- .Sa
- dbaltbind,
- dbbind,
- dberrhandle,
- dbsetnull,
- dbwillconvert,
- errors,
- types
-